<?php
set_time_limit(0);
include_once 'func.php';


//$list['list'] = [];
//
//$rn = 20;
//$pn = 0;
//while ($pn < 177) {
//
//    $url = 'https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?format=json&ie=utf-8&oe=utf-8&query=%E7%8B%97&resource_id=6829&rn=' . $rn . '&from_mid=1&pn=' . $pn . '&type_size=&type_func=&type_feat=&t=1545984930742&cb=jQuery110206682333871637092_1545984815129&_=1545984815145';
//    $result = curl_get($url);
//
//    $result = str_replace('/**/jQuery110206682333871637092_1545984815129(', '', $result);
//    $result = str_replace(');', '', $result);
//
//    $result = json_decode($result, true);
//    if(!isset($result['data'][0]['disp_data'])){
//        break;
//    }
//    foreach ($result['data'][0]['disp_data'] as $k => $v) {
//        $item['title'] = $v['name'];
//        $item['img'] = $v['img'];
//        $list['list'][] = $item;
//    }
//    $pn+= 20;
//    sleep(5);
//}
//$json_list = json_encode($list);
//file_put_contents('data.json',$json_list);


//获取图片
$list_json = file_get_contents('data.json');
$list = json_decode($list_json,true);

foreach ($list['list'] as $k=>$v){
//    $img = file_get_contents($v['img']);
//    $file_name = 'dog/d'.$k.'.png';
//    file_put_contents($file_name,$img);
    $list['list'][$k]['img'] = 'd'.$k;
}
$json_list = json_encode($list);
file_put_contents('data.json',$json_list);
//echo '<pre>';
//print_r($list);
